package com.myproject.mall.user.controller;

import com.myproject.mall.common.result.HttpResult;
import com.myproject.mall.domain.dto.CollectionGroupDTO;
import com.myproject.mall.domain.dto.PasswordForm;
import com.myproject.mall.domain.entity.User;
import com.myproject.mall.domain.vo.ShopVO;
import com.myproject.mall.domain.vo.UserVO;
import com.myproject.mall.user.service.ICollectionService;
import com.myproject.mall.user.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户接口")
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
public class UserController {

    private final IUserService userService;
    private final ICollectionService collectionService;

    @Operation(summary = "单用户查询")
    @GetMapping("/findDetail")
    public HttpResult<User> findUserDetailById(String id) {
        return HttpResult.success(userService.findUserById(id));
    }

    @Operation(summary = "用户更新资料")
    @PostMapping("/update/info")
    public HttpResult<String> updateUserInfo(User user) {
        userService.updateUserInfo(user);
        return HttpResult.success("更新成功");
    }

    @Operation(summary = "用户更新密码")
    @PostMapping("/update/password")
    public HttpResult<String> updateUserPassword(@RequestBody PasswordForm passwordForm) {
        userService.updateUserPassword(passwordForm);
        return HttpResult.success("更新成功");
    }

    @Operation(summary = "获取用户收藏组")
    @GetMapping("/get/collectionGroup")
    public HttpResult<List<CollectionGroupDTO>> getCollectionGroup()
    {
        return HttpResult.success(collectionService.getCollectionGroup());
    }

    @Operation(summary = "创建收藏组")
    @GetMapping("/create/collectionGroup")
    public HttpResult<String> createCollectionGroup(@RequestParam String groupName)
    {
        collectionService.createCollectionGroup(groupName);
        return HttpResult.success("success");
    }

    @Operation(summary = "删除收藏分组")
    @GetMapping("/delete/collectionGroup")
    public HttpResult<String> deleteCollectionGroup(@RequestParam Integer groupId) {
        collectionService.deleteCollectionGroup(groupId);
        return HttpResult.success("success");
    }

    @Operation(summary = "添加收藏")
    @GetMapping("/add/collection")
    public HttpResult<String> addCollection(@RequestParam Long goodsId, @RequestParam Integer groupId) {
        collectionService.addCollection(goodsId, groupId);
        return HttpResult.success("success");
    }

    @Operation(summary = "删除收藏")
    @GetMapping("/delete/collection")
    public HttpResult<String> deleteCollection(@RequestParam Long goodsId) {
        collectionService.deleteCollection(goodsId);
        return HttpResult.success("success");
    }

    @Operation(summary = "获取自己")
    @GetMapping("/me")
    public HttpResult<UserVO> me(){
        return HttpResult.success(userService.getMe());
    }

    @Operation(summary = "关注商店")
    @GetMapping("/follow/{isFollow}")
    public HttpResult<Void> follow(@PathVariable("isFollow") Boolean isFollow, @RequestParam Long shopId) {
        userService.follow(shopId, isFollow);
        return HttpResult.success();
    }

    @Operation(summary = "获取关注列表")
    @GetMapping("/get/followList")
    public HttpResult<List<ShopVO>> getFollowList() {
        return HttpResult.success(userService.getFollowList());
    }

    @Operation(summary = "是否已关注")
    @GetMapping("/get/isFollow")
    public HttpResult<Boolean> isFollow(@RequestParam Long shopId) {
        return HttpResult.success(userService.isFollow(shopId));
    }

}
